//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package atomgit_triger

import (
	"fmt"
	"testing"
)

const _TAG_HOOK_DATA = `
{
  "after": "92ae90114869e9f7afc90b885f867ecb9dcca3ef",
  "before": "0000000000000000000000000000000000000000",
  "commits": [
    {
      "added": [],
      "author": {
        "email": "panleiming@linksaas.pro",
        "name": "潘雷明",
        "username": "openlinksaas"
      },
      "committer": {
        "email": "panleiming@linksaas.pro",
        "name": "潘雷明",
        "username": "openlinksaas"
      },
      "distinct": true,
      "id": "9a072fc1500a0de674734e13d116b3423ff5db56",
      "message": "更新 README.md\nxxxxx",
      "modified": [
        "README.md"
      ],
      "removed": [],
      "timestamp": "2025-02-07T10:56:16Z",
      "tree_id": "af51ce59fec4d28e00a8edc40ff9869d02020437",
      "url": "https://atomgit.com/openlinksaas/test/commit/9a072fc1500a0de674734e13d116b3423ff5db56"
    },
    {
      "added": [
        ".gitignore"
      ],
      "author": {
        "email": "panleiming@linksaas.pro",
        "name": "潘雷明",
        "username": "openlinksaas"
      },
      "committer": {
        "email": "panleiming@linksaas.pro",
        "name": "潘雷明",
        "username": "openlinksaas"
      },
      "distinct": true,
      "id": "2112a8112ca33d040d72eb754c0dbbadbca6f0f1",
      "message": "Initial commit",
      "modified": [],
      "removed": [],
      "timestamp": "2025-02-07T10:53:55Z",
      "tree_id": "9f861e268d7cd34ef4faa43b35abaa246c79ca65",
      "url": "https://atomgit.com/openlinksaas/test/commit/2112a8112ca33d040d72eb754c0dbbadbca6f0f1"
    },
    {
      "added": [
        "README.md"
      ],
      "author": {
        "email": "panleiming@linksaas.pro",
        "name": "潘雷明",
        "username": "openlinksaas"
      },
      "committer": {
        "email": "panleiming@linksaas.pro",
        "name": "潘雷明",
        "username": "openlinksaas"
      },
      "distinct": true,
      "id": "8c3a855b714c763fedf533d93807ba6840671717",
      "message": "Initial commit",
      "modified": [],
      "removed": [],
      "timestamp": "2025-02-07T10:53:54Z",
      "tree_id": "3e11e671ee7d291d597d88a9214a446525ecae0c",
      "url": "https://atomgit.com/openlinksaas/test/commit/8c3a855b714c763fedf533d93807ba6840671717"
    }
  ],
  "compare": "https://atomgit.com/openlinksaas/test/compare?from=0000000000000000000000000000000000000000&to=92ae90114869e9f7afc90b885f867ecb9dcca3ef&tab=commit",
  "created": true,
  "deleted": false,
  "forced": false,
  "head_commit": {
    "added": [],
    "author": {
      "email": "panleiming@linksaas.pro",
      "name": "潘雷明",
      "username": "openlinksaas"
    },
    "committer": {
      "email": "panleiming@linksaas.pro",
      "name": "潘雷明",
      "username": "openlinksaas"
    },
    "distinct": true,
    "id": "9a072fc1500a0de674734e13d116b3423ff5db56",
    "message": "更新 README.md\nxxxxx",
    "modified": [
      "README.md"
    ],
    "removed": [],
    "timestamp": "2025-02-07T10:56:16Z",
    "tree_id": "af51ce59fec4d28e00a8edc40ff9869d02020437",
    "url": "https://atomgit.com/openlinksaas/test/commit/9a072fc1500a0de674734e13d116b3423ff5db56"
  },
  "ref": "refs/tags/v0.0.1",
  "repository": {
    "allow_forking": false,
    "archived": false,
    "clone_url": "https://atomgit.com/openlinksaas/test.git",
    "created_at": "2025-02-07T10:53:55Z",
    "default_branch": "master",
    "description": "sadfasdfasdf",
    "disabled": false,
    "fork": false,
    "forks": 0,
    "forks_count": 0,
    "full_name": "openlinksaas/test",
    "git_url": "git://atomgit.com/openlinksaas/test.git",
    "homepage": "https://atomgit.com/openlinksaas/test",
    "html_url": "https://atomgit.com/openlinksaas/test",
    "id": 37070260,
    "is_template": false,
    "language": "{\"Markdown\":\"{\\\"blank\\\":14,\\\"code\\\":18,\\\"nFiles\\\":1,\\\"comment\\\":0}\"}",
    "master_branch": "master",
    "name": "test",
    "owner": {
      "avatar_url": "https://file.atomgit.com/uploads/user/1694222084215_2176.png",
      "email": "panleiming@linksaas.pro",
      "html_url": "https://atomgit.com/openlinksaas",
      "id": "64fae54f49d9355e7a863eb6",
      "login": "openlinksaas",
      "name": "潘雷明",
      "type": "User"
    },
    "private": true,
    "size": 0.104492,
    "ssh_url": "git@atomgit.com:openlinksaas/test.git",
    "stargazers_count": 0,
    "updated_at": "2025-02-07T11:23:35Z",
    "url": "https://atomgit.com/openlinksaas/test",
    "visibility": "private"
  },
  "sender": {
    "avatar_url": "https://file.atomgit.com/uploads/user/1694222084215_2176.png",
    "html_url": "https://atomgit.com/openlinksaas",
    "id": "64fae54f49d9355e7a863eb6",
    "login": "openlinksaas",
    "type": "User"
  }
}
`

func TestExtractTagHookAttr(t *testing.T) {
	attrList, err := ExtractTagHookAttr([]byte(_TAG_HOOK_DATA))
	if err != nil {
		t.Fatal(err)
		t.FailNow()
	}
	fmt.Println(attrList)
}
